Ext.Loader.setConfig({enabled: true});
Ext.Loader.setPath({'Ext.ux' : 'extjs4/ux'});
Ext.require([
             'Ext.grid.*',
             'Ext.data.*',
             'Ext.ux.grid.FiltersFeature',
             'Ext.toolbar.Paging',
             'Ext.ux.ajax.JsonSimlet',
             'Ext.ux.ajax.SimManager',
             'Ext.ux.grid.Printer'           
]);
Ext.define('TS.view.rp.RpRecBillList',{
	extend: 'Ext.panel.Panel',
	border: false,
	bodyPadding:0,
	layout: 'border',
	alias: 'widget.rprecbilllist',
	title: '收款单列表',
	initComponent:function() {		
		this.items = [
		  		    {
				    	xtype: 'panel',
				    	title: '检索',
				    	region: 'north',
				    	height: 100,
				    	collapsible: true,
				    	border: false,
				    	buttonAlign: 'left',
				    	header: {iconCls: 'bill-search-button'},
				    	layout: 'hbox',
				    	items: [
				    	    {xtype: 'hiddenfield',name:'custId'},
				    	    {xtype: 'datefield',name:'begDate',fieldLabel: '开始日期:',format:'Y-m-d',value:new Date(),margin:'10,10,10,10'},
				    	    {xtype: 'datefield',name:'endDate',fieldLabel: '截止日期:',format:'Y-m-d',value:new Date(),margin:'10,10,10,10'},
				    	    {
				    	    	xtype: 'triggerfield',name:'customer',fieldLabel:'客户:',width:400,margin:'10,10,10,10',
				    	    	emptyText:'请输入客户编码或名称',trigger1Cls:Ext.baseCSSPrefix + 'form-search-trigger',
				    	    	onTriggerClick:function(e){e.keyCode=e.ENTER;this.fireEvent('specialkey',this,e);}
				    	    },		    	    
				    	    {xtype: 'button',text:'查询',margin:'10,10,10,10',action:'search',iconCls:'bill-find-button'},
				    	    {xtype: 'button',text:'高级检索',margin:'10,10,10,10',action:'advsearch',iconCls:'bill-search-button'}
				    	]
				    },
					{
						xtype:'gridpanel',
						title:'查询结果',
						header:false,
						border:false,
						region:'center',
						store:'rp.RecBillStore',
						selType:'checkboxmodel',//设定选择模式
						multiSelect:true,//运行多选
					    features: [{
					        ftype: 'summary'
					    },{
					        ftype: 'filters',
					        // encode and local configuration options defined previously for easier reuse
					        encode: false, // json encode the filter query
					        local: true,   // defaults to false (remote filtering)

					        filters: [{
					            type: 'string',
					            dataIndex: 'rpBillCode'
					        },{
					        	type:'date',
					        	dataIndex:'billDate'
					        },{
					        	type:'list',
					        	options:['收款单','预收单','退款单'],
					        	dataIndex:'rpBillName'
					        },{
					        	type:'string',
					        	dataIndex:'customer.customerCode'
					        },{
					        	type:'numeric',
					        	dataIndex:'amount'
					        },{
					        	type:'numeric',
					        	dataIndex:'checkAmount'
					        },{
					        	type:'boolean',
					        	dataIndex:'checkStatus'
					        },{
					        	type:'boolean',
					        	dataIndex:'archived'
					        },{
					        	type:'numeric',
					        	dataIndex:'fyear'
					        },{
					        	type:'numeric',
					        	dataIndex:'period'
					        },{
					        	type:'string',
					        	dataIndex:'remark'
					        }]			    	
					    }],					    
						columns:[
								   {header:'年份',dataIndex:'fyear',width:50,align:'right'},
								   {header:'期间',dataIndex:'period',width:50,align:'right'},
						       {
						    	   header:'单据编号',dataIndex:'rpBillCode',width:100,
						    	   summaryType:'count',summaryRenderer: function(value, summaryData, dataIndex) {return '<b>' + Ext.String.format('合计[{0}]:', value) + '</b>'; }
						       },
							   {header:'单据类型',dataIndex:'rpBillName',width:80},
							   {header:'单据日期',dataIndex:'billDate',width:80,renderer : Ext.util.Format.dateRenderer('Y-m-d')},
							   {header:'客户编码',filterable:true,width:80,renderer:function(value,metaData,record){return record.getcustomer().get('customerCode');}},
							   {header:'客户名称',width:250,renderer:function(value,metaData,record){return record.getcustomer().get('customerName');}},
							   {header:'实收金额',dataIndex:'amount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {header:'折扣',dataIndex:'discount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {header:'核销金额',dataIndex:'checkAmount',width:100,align:'right',summaryType:'sum',summaryRenderer:function(value,summaryData,dataIndex){return '<b>' + Ext.util.Format.number(value,'0,000.00') + '</b>';},renderer : Ext.util.Format.numberRenderer('0.00')},
							   {header:'核销状态',dataIndex:'checkStatus',width:80,renderer:function(value){if(value==0) return '未核销'; else return '已核销';}},
							   {header:'归档状态',dataIndex:'archived',width:60,renderer:function(value){if(value) return '是'; else return '否';}},
							   {header:'部门',width:65,renderer:function(value,metaData,record){return record.getdept().get('deptName');}},
							   {header:'业务员',width:65,renderer:function(value,metaData,record){return record.getemp().get('empName');}},
							   {header:'制单人',width:65,renderer:function(value,metaData,record){return record.getmaker().get('empName');}},
							   {header:'备注',dataIndex:'remark',width:200}
						],
						dockedItems:[{
							xtype:'pagingtoolbar',
							store:'rp.RecBillStore',
							dock:'bottom',
							displayInfo:true,
							items:[{
								text:'清除过滤条件',
								iconCls:'button-clear-filter',
								handler:function(){
									var grid = this.up('gridpanel');
									grid.filters.clearFilters();
								}
							},{
								xtype:'exporterbutton',
								component:this.up('gridpanel'),
								text:'导出 Excel',
								iconCls:'bill-export-button'
							}]
						}],
						tbar:[
								{xtype:'button',text:'新增',action:'createBill',iconCls:'bill-add-button'},
								{xtype:'button',text:'编辑',action:'editBill',iconCls:'bill-edit-button'},
								{xtype:'button',text:'删除',action:'deleteBill',iconCls:'bill-delete-button'},
								{xtype:'button',text:'归档',action:'archiveBill',iconCls:'bill-archive-button'},
								{xtype:'button',text:'反归档',action:'unArchiveBill',iconCls:'bill-unarchive-button'},
								{xtype:'button',text:'打印',action:'printBill',iconCls:'bill-printer-button'},
								{xtype:'button',text:'导出',action:'exportBill',iconCls:'bill-export-button'}					
						]
					}				
		];
		this.callParent(arguments);
	}
});